package com.liulishuo.demo.filedownloaderapplication.slice;


import com.liulishuo.demo.filedownloaderapplication.*;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;

public class MainAbilitySlice extends AbilitySlice {
    public final String TAG = MainAbilitySlice.class.getSimpleName();
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        findComponentById(ResourceTable.Id_bt_multi_task).setClickedListener((view)->{
            startAbility(MultiTaskTestAbility.class);
            /*
            Operation operation = new Intent.OperationBuilder().withAction("action.app.MultitaskTestAbility").build();
            Intent taskIntent=new Intent();
            taskIntent.setAction("action.app.MultitaskTestAbility");
            //taskIntent.setOperation(operation);
            startAbility(taskIntent);
             */
        });
        findComponentById(ResourceTable.Id_bt_single_task).setClickedListener((view)->{
            startAbility(SingleTaskAbility.class);
        });
        findComponentById(ResourceTable.Id_bt_hybrid_task).setClickedListener((view)->{
            startAbility(HybridTestAbility.class);
        });
        findComponentById(ResourceTable.Id_bt_task_manager).setClickedListener((view)->{
            startAbility(TaskManagerDemoAbility.class);
        });
        findComponentById(ResourceTable.Id_bt_notification_sample).setClickedListener((view)->{
            startAbility(NotificationSampleAbility.class);
        });
    }

    private void startAbility(Class clazz) {
        Intent multiTaskIntent = new Intent();
        Operation operation=  new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName(clazz.getPackage().getName())
                .withAbilityName(clazz.getCanonicalName()).build();
        multiTaskIntent.setOperation(operation);
        startAbility(multiTaskIntent);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
